import string


class Converter:
    def __init__(self):
        self.letters = string.digits + string.ascii_lowercase + string.ascii_uppercase + string.punctuation
        self.length = len(self.letters)

    def to_string(self, index):
        result = ""

        while True:
            quotient, remainder = divmod(index, self.length)
            result = self.letters[remainder] + result
            if quotient == 0:
                break
            index = quotient - 1

        return result

    def to_decimal(self, base_str):
        decimal_num = 0
        for i, char in enumerate(base_str):
            power = len(base_str) - 1 - i
            if power == 0:
                decimal_num += self.letters.index(char)
                continue
            decimal_num += self.length ** power * (self.letters.index(char) + 1)
        return decimal_num


if __name__ == '__main__':
    converter = Converter()

    converter.to_string(94)

    for i in range(18800):
        string = converter.to_string(i)

        print(i, "->", string, "->", converter.to_decimal(string))

    string = "~~~~~~~~~~~~~~~~"
    print(string, "->", end=" ")
    decimal = converter.to_decimal(string)
    print(decimal, "->", end=" ")
    string = converter.to_string(decimal)
    print(string)
